package com.group.sliding.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.sliding.domain.po.Address;
import com.group.sliding.domain.query.AddressPageQuery;
import com.group.sliding.result.PageDTO;
import com.group.sliding.result.Result;
import com.group.sliding.service.IAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "管理员地址管理相关接口")
@RestController
@RequestMapping("/admin/addresses")
@RequiredArgsConstructor
public class AdminAddressController {
    private final IAddressService addressService;

    @ApiOperation("分页查询用户地址")
    @GetMapping("/page")
    public Result<PageDTO<Address>> queryAddressByPage(AddressPageQuery query) {
        log.info("分页查询用户地址 {}", query);
        Page<Address> pageResult = addressService.search(query);
        PageDTO<Address> result = PageDTO.of(pageResult, Address.class);
        log.info("分页查询用户地址结果 {}", result);
        return Result.success(result);
    }
}
